package com.tongqu.Test;

import com.alibaba.fastjson.JSON;
import com.tongqu.entity.Login;
import com.tongqu.message.LoginMessage;
import com.tongqu.protocol.MessageCodec;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;
@Component
public class Test {
    public static void main(String[] args) throws Exception {
        LoggingHandler LOGGING_HANDLER = new LoggingHandler(LogLevel.DEBUG);
        EmbeddedChannel channel = new EmbeddedChannel(
                LOGGING_HANDLER,new MessageCodec());
        Login acct = new Login("aaa", "123");
        LoginMessage user = new LoginMessage(1,acct);
        channel.writeOutbound(user);


        ByteBuf buf = ByteBufAllocator.DEFAULT.buffer();

        String json= JSON.toJSONString(user);
        byte[] bytes = json.getBytes(StandardCharsets.UTF_8);

        channel.writeInbound(buf.writeBytes(bytes));

    }
}
